var i = 0;
setInterval(function() {
    $('#cloud').css('background-position', i + 'px 0px');
    if (++i > 1200) {
        i = 0;
    }
}, 60);

var pkey = '-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvQwXZwuyR0RawUe7PybF2iJOaTVLsaWoIVv7KVsq7e3AD/IRUgh8Ff/wGs9SdPEhNH8chxp2XqYgHTRMCXsa0dGcNsURCB5wTu5WDqanq/etvWxLD8oD4K897L9xsK56UKnc73icrCrYPPol+wkoyA9pawHPur+P1CImgFcGS1PQuOB00tch3N5MtXUDHtXE4cKocEuqQ1mbJylY3ybsgRhkUW7/k9fjWdOvmuHToiq6767x3wKzPVMX62b4XUzG1eT2zZarlQPsMuCkoKFAJg3mkzlIr4JdrWhXR+Nunme5fKxCw4r4zcJ0vR5dShy3KZAcBEEL81GelyKwOJAreQIDAQAB-----END PUBLIC KEY-----',
    rsa = new JSEncrypt();
rsa.setPublicKey(pkey);

$('#code_img').click(function() {
    $(this).attr('src', 'update_pwd.php?do=code&amp;' + Math.random());
});

$('#dologin').click(function() {
    var name = $.trim($("#name").val());
    var pwd = $.trim($("#pwd").val());
    var pwds = $.trim($("#pwds").val());
    var code = $.trim($("#code").val());
    var pwsold = $.trim($("#pwsold").val());
    if (pwsold == '') {
        sweetAlert('出错了', '旧密码不可为空', 'error');
        return false;
    }
    if (pwd.length < 7  || pwd != pwds) {
        sweetAlert('出错了', '2次密码输入不一致 或长度小于7位数', 'error');
        return false;
    }
    if ((code == '' && $("#dologin").attr('data-env') == 'ONLINE')) {
        sweetAlert('出错了', '验证码错误', 'error');
        return false;
    }else {
        $.ajax({
            url: 'update_pwd.php?do=UpdatePwd',
            type: "post",
            dataType: "json",
            data:{'name': name, 'pwd': pwd, 'code': code, 'pwds':pwds, 'pwsold': rsa.encrypt(pwsold)},
            success:function(re) {
                if (re.type == 'success') {
                    top.swal(re,function(){
                      top.location.href = 'admin.php';
                    });
                } else {
                    sweetAlert(re);
                    $('#code_img').click();
                }
            }
        })
    }
    return false;
});
